<?php
// +----------------------------------------------------------------------
// | 商家模块
// +----------------------------------------------------------------------

namespace app\mall\model;

use think\Model as ThinkModel;
use util\Tree;
use think\facade\Db;

/**
 * 分类模型
 * @package app\mall\model
 */
class Qrcode extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'mall_qrcode';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

	
    /**
     * 获取指定二维码数据
     * @param int $id 二维码id
     * @return mixed|static
     */
    public static function getInfo($id = 0) 
    {
        $result = cache('mall_qrcode_info_'. $id);
		$scan = cache('scan_'.$id);
        if (!$result) {
            $result = self::where('id', $id)->where('status', 1)->find();
            // 非开发模式，缓存数据
            if (config('app.develop_mode') == 0) {
                cache('mall_qrcode_info_'. $id, $result);
            }
        }
		$scan++;
		if ($scan >= 5){
			self::where('id', $id)->inc('view', $scan)->update();
			cache('scan_'.$id, 0);
		} else {
			cache('scan_'.$id, $scan);
		}
        return $result;
    }
}